import apiClient from './index';

// 班级列表项类型
export interface ClassItem {
  grade: number;
  id: number;
  name: string;
}

// 班级列表响应类型
export interface ListClassesResponse {
  code: number;
  content: ClassItem[];
  msg: string;
}

// 设置班主任参数
export interface SetHeadTeacherParams {
  class_id: number;
  teacher_id: number;
  admin_password: string;
}

// 设置班主任响应类型
export interface SetHeadTeacherResponse {
  code: number;
  msg: string;
}

/**
 * 获取未毕业班级列表
 */
export const listClasses = async (): Promise<ListClassesResponse> => {
  const response = await apiClient.post<ListClassesResponse>('/classmgr/list-classes', {
     is_graduated: 0
  });
  return response.data;
};

/**
 * 设置班主任
 */
export const setHeadTeacher = async (
  params: SetHeadTeacherParams
): Promise<SetHeadTeacherResponse> => {
  const response = await apiClient.post<SetHeadTeacherResponse>('/classmgr/set-head-teacher', params);
  return response.data;
};

// 设置班级任课老师参数
export interface SetSubjectTeacherParams {
  class_id: number;
  teacher_id: number;
  subject: string;
  admin_password: string;
}

// 设置班级任课老师响应类型
export interface SetSubjectTeacherResponse {
  code: number;
  msg: string;
  content: {
    class_id: number;
    subject: string;
    teacher_id: number;
    teacher_name: string;
  };
}

/**
 * 设置班级任课老师
 */
export const setSubjectTeacher = async (
  params: SetSubjectTeacherParams
): Promise<SetSubjectTeacherResponse> => {
  const response = await apiClient.post<SetSubjectTeacherResponse>('/classmgr/set-subject-teacher', params);
  return response.data;
};

// 获取班级任课老师请求参数
export interface GetSubjectTeacherParams {
  class_id: number;
}

// 获取班级任课老师响应类型
export interface SubjectTeacherItem {
  subject: string,
  id: number,
  teacher_id: number,
  teacher_name: string,
  user_id: number
}

export interface GetSubjectTeacherResponse {
  code: number;
  msg: string;
  content: SubjectTeacherItem[];
}

/**
 * 获取班级任课老师列表
 */
export const getSubjectTeacher = async (
  params: GetSubjectTeacherParams
): Promise<GetSubjectTeacherResponse> => {
  const response = await apiClient.post<GetSubjectTeacherResponse>('/classmgr/get-subject-teacher', params);
  return response.data;
};
